package cn.gson.springboot.model.pojos;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Objects;

@Entity
@Table(name = "product_classify", schema = "crm")
public class ProductClassify {
    private int productClassifyId;
    private String productClassifyName;
    private ProductClassify classifyFather;
    private Integer classifyWhether;
    private List<Product> productsByProductClassifyId;
    private List<ProductClassify> children;

    @Id
    @Column(name = "product_classify_id", nullable = false)
    public int getProductClassifyId() {
        return productClassifyId;
    }

    public void setProductClassifyId(int productClassifyId) {
        this.productClassifyId = productClassifyId;
    }

    @Basic
    @Column(name = "product_classify_name", nullable = true, length = 255)
    public String getProductClassifyName() {
        return productClassifyName;
    }

    public void setProductClassifyName(String productClassifyName) {
        this.productClassifyName = productClassifyName;
    }

    @Basic
    @Column(name = "classify_whether", nullable = true)
    public Integer getClassifyWhether() {
        return classifyWhether;
    }

    public void setClassifyWhether(Integer classifyWhether) {
        this.classifyWhether = classifyWhether;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        ProductClassify that = (ProductClassify) o;
        return productClassifyId == that.productClassifyId &&
                Objects.equals(productClassifyName, that.productClassifyName) &&
                Objects.equals(classifyWhether, that.classifyWhether);
    }

    @Override
    public int hashCode() {
        return Objects.hash(productClassifyId, productClassifyName, classifyWhether);
    }

    @OneToMany(mappedBy = "productClassifyByProductClassifyId")
    public List<Product> getProductsByProductClassifyId() {
        return productsByProductClassifyId;
    }

    public void setProductsByProductClassifyId(List<Product> productsByProductClassifyId) {
        this.productsByProductClassifyId = productsByProductClassifyId;
    }

    @ManyToOne
    @JoinColumn(name = "classify_Father", referencedColumnName = "product_classify_id")
    public ProductClassify getClassifyFather() {
        return classifyFather;
    }

    public void setClassifyFather(ProductClassify classifyFather) {
        this.classifyFather = classifyFather;
    }

    @OneToMany(mappedBy="classifyFather", cascade=CascadeType.REMOVE, fetch=FetchType.LAZY)
    public List<ProductClassify> getChildren() {
        return children;
    }

    public void setChildren(List<ProductClassify> children) {
        this.children = children;
    }

    @Override
    public String toString() {
        return "ProductClassify{" +
                "productClassifyId=" + productClassifyId +
                ", productClassifyName='" + productClassifyName + '\'' +
                ", classifyFather=" + classifyFather +
                ", classifyWhether=" + classifyWhether +
                ", productsByProductClassifyId=" + productsByProductClassifyId +
                ", children=" + children +
                '}';
    }
}

